package com.spring.authManage.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.spring.authManage.dao.ResourceInfoDao;
import com.spring.authManage.pojo.ResourceInfo;
import com.spring.authManage.pojo.ResourceInfoParam;
import com.spring.common.dao.MySqlBaseDao;

@Repository("resourceInfoDao")
public class ResourceDaoImpl extends MySqlBaseDao implements ResourceInfoDao{

	/**
	 * 添加资源
	 * @param resourceInfo
	 * @return
	 */
	public void addResource(ResourceInfo resourceInfo) throws Exception {
		this.getSqlMapClientTemplate().insert("addResource",resourceInfo);
	}
	/**
	 * 更改资源信息
	 * @param resourceInfo
	 * @return
	 */
	public void updateResource(ResourceInfo resourceInfo) throws Exception {
		this.getSqlMapClientTemplate().update("updateResource",resourceInfo);	
	}
	/**
	 * 作废资源
	 * @param resourceInfo
	 * @return
	 */
	public void deleteResource(String res_id) throws Exception {
		this.getSqlMapClientTemplate().delete("deleteResource",res_id);
	}
	/**
	 * 重启资源
	 * @param resourceInfo
	 * @return
	 */
	public void restartResourceInfo(String res_id) throws Exception {
		this.getSqlMapClientTemplate().update("restartResource",res_id);
	}
	/**
	 * 查询是否已存在相同资源
	 * @param resourceInfo
	 * @return
	 */
	public Integer existResource(ResourceInfo resourceInfo) throws Exception {
		Integer countnub = (Integer) this.getSqlMapClientTemplate().queryForObject("existResource",resourceInfo);
		return countnub;
	}
	/**
	 * 计算分页
	 * @param resourceInfo
	 * @return
	 */
	public Integer countResourceByParam(ResourceInfoParam resourceInfoParam) throws Exception {
		Integer resultnub = (Integer) this.getSqlMapClientTemplate().queryForObject("countResourceByParam",resourceInfoParam);
		return resultnub;

	}
	/**
	 * 根据条件查询资源
	 * @param resourceInfo
	 * @return
	 */ 
	public List<ResourceInfo> queryResourceByParam(ResourceInfoParam resourceInfoParam) throws Exception {
		List<ResourceInfo> resourceInfoFirst = this.getSqlMapClientTemplate().queryForList("queryResourceByParam",resourceInfoParam);
		return resourceInfoFirst;
	}
	/**
	 * 根据用户名获取一级菜单二级菜单
	 * @param userName
	 * @return List<String>
	 */
	public List<ResourceInfo> getFirstTextByUserName(String userName) throws Exception {
		List<ResourceInfo> resourceInfoList = this.getSqlMapClientTemplate().queryForList("getFirstTextByUserName",userName);
		return resourceInfoList;
	}
	/**
	 * 进去资源管理页面初始查询所有一级菜单
	 * 
	 * @return
	 */
	public List<ResourceInfo> queryFirstLevel(ResourceInfoParam param) throws Exception {
		List<ResourceInfo> resourceInfoList = this.getSqlMapClientTemplate().queryForList("queryFirstLevel",param);
		return resourceInfoList;
	}
	/**
	 * 点击一级菜单查询附属二级菜单详细
	 * @param id
	 * @return
	 */
	public List<ResourceInfo> querySecondLevel(String id) throws Exception {
		List<ResourceInfo> resourceInfoList = this.getSqlMapClientTemplate().queryForList("querySecondLevel",id);
		return resourceInfoList;
	}
	/**
	 * 查询所有父资源name,id
	 * @param id
	 * @return
	 */
	public List<ResourceInfo> queryParentResource() throws Exception {
		List<ResourceInfo> resourceInfoList = this.getSqlMapClientTemplate().queryForList("queryParentResource");
		return resourceInfoList;
	}
	/**
	 * 根据父资源name查询id
	 * @param id
	 * @return
	 */
	public List<ResourceInfo> getParentId(String parentName) throws Exception {
		List<ResourceInfo> resourceInfoList = this.getSqlMapClientTemplate().queryForList("getParentId",parentName);
		return resourceInfoList;
	}
	/**
	 * 获取所有可用的资源
	 * @return
	 */
	public List<ResourceInfo> getAllEnabledResource() throws Exception {
		List<ResourceInfo> resourceInfoList = this.getSqlMapClientTemplate().queryForList("getAllEnabledResource");
		return resourceInfoList;
	}
	/**
	 * 根据ID获取权限具体信息
	 * @param id
	 * @return
	 */
	public ResourceInfo queryResourceById(String id) {
		ResourceInfo resourceInfo = (ResourceInfo)this.getSqlMapClientTemplate().queryForObject("queryResourceById", id);
		return resourceInfo;
	}
	/**
	 * 根据角色获取该角色拥有的权限
	 * @param roleId
	 * @return
	 */
	public List<ResourceInfo> getResourceByRole(String roleId) {
		List<ResourceInfo> resourceInfoList = this.getSqlMapClientTemplate().queryForList("getResourceByRole",roleId);
		return resourceInfoList;
	}
	/**
	 * 根据用户获取用户所拥有的权限
	 * @param userId
	 * @return
	 */
	public List<ResourceInfo> getResourceByUser(String userId) {
		List<ResourceInfo> resourceInfoList = this.getSqlMapClientTemplate().queryForList("getResourceByUser",userId);
		return resourceInfoList;
	}
	/**
	 * 动态生成菜单
	 * @param param
	 * @return
	 */
	public List<ResourceInfo> getMenuByUserName(String userName) throws Exception{
		return (List<ResourceInfo>)this.getSqlMapClientTemplate().queryForList("getMenuByUserName",userName);
	}
}
